package com.lzf.yh.userService.impl;

import com.lzf.yh.commons.JsonBean;
import com.lzf.yh.dao.ShoppingCartMapper;
import com.lzf.yh.entity.ShoppingCart;
import com.lzf.yh.userService.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: Wyz
 * @Date: 2021/4/18 16:20
 * @Description:
 */
@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {


    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    @Override
    public JsonBean selectAllShoppingCart(Integer userid) {
        return new JsonBean(0,"",shoppingCartMapper.selectAllShoppingCart(userid));
    }

    @Override
    public JsonBean insert(ShoppingCart record) {
        JsonBean jsonBean = new JsonBean(-1, "收藏失败，请重试", null);
        ShoppingCart shoppingCart = shoppingCartMapper.selectOneShoppingCartByGuitarnameAndUserid(record);
        if (shoppingCart!=null){
            jsonBean = new JsonBean(-1, "您已收藏此商品，请勿重复操作", null);
        }else {
            int insert = shoppingCartMapper.insert(record);
            if (insert>0){
                jsonBean = new JsonBean(0, "收藏成功", null);
            }
        }
        return jsonBean;
    }

    @Override
    public JsonBean deleteShoppingCartById(Integer id) {

        JsonBean jsonBean = new JsonBean(-1, "删除失败，请稍后再试", null);
        int i = shoppingCartMapper.deleteByPrimaryKey(id);
        if (i>0){
            jsonBean = new JsonBean(0, "删除成功", null);
        }
        return jsonBean;
    }
}
